<?php
namespace app\common\controller;
use think\Controller;
use think\Session;
class Carddate extends Controller
{


    //数据字段处理



    /*
     * 创建会员卡
     * $arr 主要数据
     * $type 处理类型 接口/存储
     * $data 存储使用
     * $res 存储使用
     *
     */
    public function addcard($arr,$type,$data = '',$res = ''){
        if ($type == 1){
            $data['card']['card_type'] = "MEMBER_CARD";                                                            //卡券类型 会员卡
            $data['card']['member_card']['background_pic_url'] = $arr['background_pic_url'];                       //卡面图片url
            //基础字段
            $data['card']['member_card']['base_info'] = $this->base_info($arr['base']);                             //卡券基本信息
            $data['card']['member_card']['prerogative'] = $arr['prerogative'];                                      //会员卡特权说明,限制1024汉字。
            $data['card']['member_card']['supply_bonus'] = $arr['supply_bonus'] == 1 ? true:false;                                          //是否积分
            $data['card']['member_card']['supply_balance'] = $arr['supply_balance'] == 1 ? true:false;                                      //是否余额
            //自定义栏目3
            if(isset($arr['is_cell1'])) {
                if ($arr['is_cell1'] == 1) {
                    $data['card']['member_card']['base_info']['custom_url_name'] = $arr['custom_cell1']['name'];
                    $data['card']['member_card']['base_info']['custom_url_sub_title'] = $arr['custom_cell1']['tips'];
                    $data['card']['member_card']['base_info']['custom_url'] = $arr['custom_cell1']['url'];
                } else {
                    $data['card']['member_card']['base_info']['custom_url_name'] = '';
                    $data['card']['member_card']['base_info']['custom_url_sub_title'] = '';
                    $data['card']['member_card']['base_info']['custom_url'] = '';
                }
            }

            //营销入口
            if(isset($arr['is_cell4'])) {
                if ($arr['is_cell4'] == 1) {
                    $data['card']['member_card']['base_info']['promotion_url_name'] = $arr['custom_cell4']['name'];
                    $data['card']['member_card']['base_info']['promotion_url'] = $arr['custom_cell4']['url'];
                    $data['card']['member_card']['base_info']['promotion_url_sub_title'] = $arr['custom_cell4']['tips'];
                } else {
                    $data['card']['member_card']['base_info']['promotion_url_name'] = '';
                    $data['card']['member_card']['base_info']['promotion_url'] = '';
                    $data['card']['member_card']['base_info']['promotion_url_sub_title'] = '';
                }
            }
            //积分字段
            if ($arr['supply_bonus'] == 1){
                if (isset($arr['bonus'])){
                    $data['card']['member_card']['bonus_rule'] = $this->bonus_rule($arr['bonus']);
                }
            }
            $data['card']['member_card']['supply_balance'] = $arr['supply_balance'] == 1 ? true:false;                                        //是否储值
            //自定义类目1
            if (isset($arr['custom_field1'])){
                if ($arr['is_field1'] == 1){
                    $data['card']['member_card']['custom_field1']['name_type'] = $arr['custom_field1']['name'];
                    if (isset($arr['custom_field1']['url'])){
                        $data['card']['member_card']['custom_field1']['url'] = $arr['custom_field1']['url'];
                    }

                }
            }
            //自定义类目1
            if (isset($arr['is_field2'])){
                if ($arr['is_field2'] == 1){
                    if (isset($arr['custom_field2']['name'])){
                        $data['card']['member_card']['custom_field2']['name'] = $arr['custom_field2']['name'];
                    }else{
                        $data['card']['member_card']['custom_field2']['name'] = $arr['custom_field2']['name'];
                    }

                    if (isset($arr['custom_field2']['url'])){
                        $data['card']['member_card']['custom_field2']['url'] = $arr['custom_field2']['url'];
                    }
                }
            }
            //自定义类目1
            if (isset($arr['is_field3'])){
                if ($arr['is_field3'] == 1){
                    if (isset($arr['custom_field3']['name'])){
                        $data['card']['member_card']['custom_field3']['name'] = $arr['custom_field3']['name'];
                    }else{
                        $data['card']['member_card']['custom_field3']['name'] = $arr['custom_field3']['name'];
                    }

                    if (isset($arr['custom_field2']['url'])){
                        $data['card']['member_card']['custom_field3']['url'] = $arr['custom_field3']['url'];
                    }
                }
            }
            //自定义类目1
            if(isset($arr['is_cell2'])){
                if ($arr['is_cell2'] == 1){
                    $data['card']['member_card']['custom_cell1']['name'] = $arr['custom_cell2']['name'];
                    $data['card']['member_card']['custom_cell1']['tips'] = $arr['custom_cell2']['tips'];
                    $data['card']['member_card']['custom_cell1']['url'] = $arr['custom_cell2']['url'];
                }
            }
            //自定义类目1
            if(isset($arr['is_cell3'])){
                if ($arr['is_cell3'] == 1){
                    $data['card']['member_card']['custom_cell2']['name'] = $arr['custom_cell3']['name'];
                    $data['card']['member_card']['custom_cell2']['tips'] = $arr['custom_cell3']['tips'];
                    $data['card']['member_card']['custom_cell2']['url'] = $arr['custom_cell3']['url'];
                }
            }
            //自定义类目3
//            if(isset($arr['is_cell3'])){
//                if ($arr['is_cell3'] == 1){
//                    $data['card']['member_card']['custom_cell3']['name'] = $arr['custom_cell3']['name'];
//                    $data['card']['member_card']['custom_cell3']['tips'] = $arr['custom_cell3']['tips'];
//                    $data['card']['member_card']['custom_cell3']['url'] = $arr['custom_cell3']['url'];
//                }
//            }
//            //会员卡激活
//            if($arr['activate'] == 1){$data['card']['member_card']['auto_activate'] = true;}                        //自动激活
//            if($arr['activate'] == 0){
            $data['card']['member_card']['wx_activate'] = true;                                                 //一键激活
            //           }
            //会员卡折扣字段
            if ($arr['is_discount'] == 1){
                $data['card']['member_card']['discount'] = 100-$arr['discount'];                                            //几折
            }
            return $data;
        }
        if ($type == 2){
            $adata['mid'] = $arr['mid'];                                                                                      //商户ID
            $adata['top_mid'] = Session::get('login_top_mid');
            $adata['brand_name'] = $data['card']['member_card']['base_info']['brand_name'];
            $adata['card_type'] = 'MEMBER_CARD';                                                                    //类型
            $adata['logo_url'] = $data['card']['member_card']['base_info']['logo_url'];                             //LOGO
            $adata['title'] = $data['card']['member_card']['base_info']['title'];                                   //名称
            $adata['pic_url'] = $data['card']['member_card']['background_pic_url'];                                 //卡面图片url
            $adata['color'] = $arr['base']['color'];                                                           //颜色
            $adata['base_info'] = json_encode($data['card']['member_card']['base_info'],JSON_UNESCAPED_UNICODE);        //卡券基本信息
            $adata['card_id'] = $res['card_id'];                                                                                //卡券ID
            $adata['supply_bonus'] = $arr['supply_bonus'];
            $adata['is_dedu_cards'] = 1;
            $adata['supply_balance'] = $arr['supply_balance'];
            $adata['center_type'] = $arr['base']['is_center'];
            $adata['is_center'] = $arr['base']['is_center'];
            $adata['is_cell1'] = $arr['is_cell1'];
            $adata['is_cell2'] = $arr['is_cell2'];
            $adata['is_cell3'] = $arr['is_cell3'];
            $adata['is_cell4'] = $arr['is_cell4'];
            $adata['is_money'] = 1;         //开启余额
//            $adata['is_rank'] = 1;        //开启等级
            //        $adata['is_cell2'] = $arr['is_cell3'];
            $adata['is_field2'] = $arr['is_field2'];
            $adata['is_field3'] = $arr['is_field3'];
            $adata['is_locations'] = $arr['base']['is_locations'];
//            $adata['is_pro'] = $arr['base']['is_pro'];
//            $adata['is_custom'] = $arr['base']['is_custom'];
            $adata['is_center'] = $arr['base']['is_center'];
            if ($arr['base']['is_center'] == 1){
                if ($arr['base']['center'] == 9){
                    $adata['center_pay'] = 9;
                }else{
                    $adata['center_pay'] = 6;
                }
            }

            if ($arr['supply_bonus'] == 1) {
                if (isset($arr['bonus'])){
                    $adata['is_bonus'] = 1;
                    $adata['bonus_rule'] = json_encode($arr['bonus'], JSON_UNESCAPED_UNICODE);
                }
            }
//            if (isset($arr['is_field1'])){
//                if ($arr['is_field1'] == 1) {
//                    $adata['custom_field1'] = json_encode($arr['custom_field1'], JSON_UNESCAPED_UNICODE);
//                }
//            }
            if (isset($arr['is_field2'])) {
                if ($arr['is_field2'] == 1) {
                    $adata['custom_field2'] = json_encode($arr['custom_field2'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_field3'])) {
                if ($arr['is_field3'] == 1) {
                    $adata['custom_field3'] = json_encode($arr['custom_field3'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_cell1'])){
                if ($arr['is_cell1'] == 1) {
                    $adata['custom_cell1'] = json_encode($arr['custom_cell1'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_cell2'])){
                if ($arr['is_cell2'] == 1) {
                    $adata['custom_cell2'] = json_encode($arr['custom_cell2'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_cell3'])){
                if ($arr['is_cell3'] == 1) {
                    $adata['custom_cell3'] = json_encode($arr['custom_cell3'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_cell4'])){
                if ($arr['is_cell4'] == 1) {
                    $adata['custom_cell4'] = json_encode($arr['custom_cell4'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_discount'])) {
                if ($arr['is_discount'] == 1) {
                    $adata['discount'] = $arr['discount'];                                            //几折
                }
                $adata['is_discount'] = $arr['is_discount'];
//                else{
//                    $adata['discount'] = 100;
//                }

            }
            $adata['prerogative'] = $arr['prerogative'];                                                                        //会员卡特权说明,限制1024汉字。
            $adata['statu'] = 0;                                                                                                //状态
            $adata['stocks'] = $data['card']['member_card']['base_info']['sku']['quantity'];                                    //库存
            $adata['activate'] = $arr['activate'];                                                                              //激活： 1/0  自动/一键
            $adata['fire'] = $arr['activate'] == 1? 1:0;                                                                        //激活状态  需不需要提交激活字段
            $adata['create_time'] = time();
            return $adata;
        }
    }

    //修改会员卡
    /*
     * $arr 主要数据
     * $type 处理类型 接口/存储
     * $info 存储使用
     *
     * */
    public function editcard($arr,$type,$info="")
    {
        if ($type == 1) {
            $data['card_id'] = $arr['card_id'];
            $data['member_card']['background_pic_url'] = $arr['background_pic_url'];                    //卡面图片url
            $data['member_card']['base_info'] = $this->ebase_info($arr['base']);                         //卡券基本信息
            //自定义栏目3
            if(isset($arr['is_cell1'])) {
                if ($arr['is_cell1'] == 1) {
                    $data['member_card']['base_info']['custom_url_name'] = $arr['custom_cell1']['name'];
                    $data['member_card']['base_info']['custom_url_sub_title'] = $arr['custom_cell1']['tips'];
                    $data['member_card']['base_info']['custom_url'] = $arr['custom_cell1']['url'];
                } else {
                    $data['member_card']['base_info']['custom_url_name'] = '';
                    $data['member_card']['base_info']['custom_url_sub_title'] = '';
                    $data['member_card']['base_info']['custom_url'] = '';
                }
            }

            //营销入口
            if(isset($arr['is_cell4'])) {
                if ($arr['is_cell4'] == 1) {
                    $data['member_card']['base_info']['promotion_url_name'] = $arr['custom_cell4']['name'];
                    $data['member_card']['base_info']['promotion_url'] = $arr['custom_cell4']['url'];
                    $data['member_card']['base_info']['promotion_url_sub_title'] = $arr['custom_cell4']['tips'];
                } else {
                    $data['member_card']['base_info']['promotion_url_name'] = '';
                    $data['member_card']['base_info']['promotion_url'] = '';
                    $data['member_card']['base_info']['promotion_url_sub_title'] = '';
                }
            }

            //         $data['member_card']['prerogative'] = $arr['prerogative'];
            $data['member_card']['supply_bonus'] = $arr['supply_bonus'] == 1 ? true:false;                                          //是否积分
            $data['member_card']['supply_balance'] = $arr['supply_balance'] == 1 ? true:false;                                      //是否余额
            //积分字段
            if ($arr['supply_bonus'] == 1){
                if (isset($arr['bonus'])){
                    $data['member_card']['bonus_rule'] = $this->bonus_rule($arr['bonus']);
                }
            }
            $adata['is_center'] = $arr['base']['is_center'];
            $arr['is_field2'] = 1;
            if ($arr['is_field2'] == 1){
//                $data['member_card']['custom_field2']['name_type'] = $arr['custom_field2']['name_type'];
                $data['member_card']['custom_field2']['url'] = $arr['custom_field2']['url'];
            }
            if (isset($arr['custom_field1'])){
                if ($arr['is_field1'] == 1){
                    $data['member_card']['custom_field1']['name_type'] = $arr['custom_field1']['name_type'];
                    if (isset($arr['custom_field1']['url'])){
                        $data['member_card']['custom_field1']['url'] = $arr['custom_field1']['url'];
                    }
                }
            }
            //自定义类目2
            if (isset($arr['is_field2'])){
                if ($arr['is_field2'] == 1){
                    if (isset($arr['custom_field2']['name_type'])){
                        $data['member_card']['custom_field2']['name_type'] = $arr['custom_field2']['name_type'];
                    }else{
                        $data['member_card']['custom_field2']['name'] = $arr['custom_field2']['name'];
                    }
                    if (isset($arr['custom_field2']['url'])){
                        $data['member_card']['custom_field2']['url'] = $arr['custom_field2']['url'];
                    }
                }
            }
            //自定义类目3
            if (isset($arr['is_field3'])){
                if ($arr['is_field3'] == 1){
                    if (isset($arr['custom_field3']['name_type'])){
                        $data['member_card']['custom_field3']['name_type'] = $arr['custom_field3']['name_type'];
                    }else{
                        $data['member_card']['custom_field3']['name'] = $arr['custom_field3']['name'];
                    }
                    if (isset($arr['custom_field3']['url'])){
                        $data['member_card']['custom_field3']['url'] = $arr['custom_field3']['url'];
                    }
                }
                if ($arr['is_field3'] == 2){
//                    $data['member_card']['custom_field3']['name_type']  = '';
                    $data['member_card']['custom_field3']['name'] = '';
                    $data['member_card']['custom_field3']['url'] = '';
                }
            }
            //自定义类目1
            if(isset($arr['is_cell2'])){
                if ($arr['is_cell2'] == 1){
                    $data['member_card']['custom_cell1']['name'] = $arr['custom_cell2']['name'];
                    $data['member_card']['custom_cell1']['tips'] = $arr['custom_cell2']['tips'];
                    $data['member_card']['custom_cell1']['url'] = $arr['custom_cell2']['url'];
                }else{
                    $data['member_card']['custom_cell1']['name'] = '';
                    $data['member_card']['custom_cell1']['tips'] = '';
                    $data['member_card']['custom_cell1']['url'] = '';
                }
            }
            //自定义类目1
            if(isset($arr['is_cell3'])){
                if ($arr['is_cell3'] == 1){
                    $data['member_card']['custom_cell2']['name'] = $arr['custom_cell3']['name'];
                    $data['member_card']['custom_cell2']['tips'] = $arr['custom_cell3']['tips'];
                    $data['member_card']['custom_cell2']['url'] = $arr['custom_cell3']['url'];
                }else{
                    $data['member_card']['custom_cell2']['name'] = '';
                    $data['member_card']['custom_cell2']['tips'] = '';
                    $data['member_card']['custom_cell2']['url'] = '';
                }
            }

            //自定义类目1
//            if(isset($arr['is_cell3'])){
//                if ($arr['is_cell3'] == 1){
//                    $data['member_card']['custom_cell3']['name'] = $arr['custom_cell3']['name'];
//                    $data['member_card']['custom_cell3']['tips'] = $arr['custom_cell3']['tips'];
//                    $data['member_card']['custom_cell3']['url'] = $arr['custom_cell3']['url'];
//                }
//            }
            $data['member_card']['prerogative'] = $arr['prerogative'];                                  //会员卡特权说明,限制1024汉字。
            if ($arr['is_discount'] == 1) {
                $data['member_card']['discount'] = 100-$arr['discount'];
            }
            return $data;
        }
        if ($type == 2) {
            $base = json_decode($info['base_info'], true);                                       //原始基本信息
            $udata['logo_url_abs'] = $arr['logo_url_abs'];                                                    //logo绝对地址
            $udata['bg_url_abs'] = $arr['bg_url_abs'];                                                        //背景图片绝对地址
            $udata['logo_url'] = $arr['base']['logo_url'];                                                    //logo
            $udata['title'] = $arr['base']['title'];                                                   //名称
            $udata['pic_url'] = $arr['background_pic_url'];                                            //卡面图片url
            $udata['color'] = $arr['base']['color'];                                  //颜色
            $udata['brand_name'] = $base['brand_name'];
            //要修改的基本信息
            $udata['base_info'] = [
                "brand_name" => $base['brand_name'],                                                    //商家名称
                "logo_url" => $arr['base']['logo_url'],                                                        //logo
                "code_type" => $arr['base']['code_type'],                                                      //code展示类型
                "service_phone" => $arr['base']['service_phone'],                                              //客服电话
                "title" => $arr['base']['title'],                                                       //名称
                "color" => $arr['base']['color'],                                                       //颜色
                "get_limit" => $arr['base']['get_limit'],                                               //单人可领取
                "date_info" => array(                                                                   //时间类型
                    "type" => "DATE_TYPE_PERMANENT"
                ),
                "sku" => array(                                                                         //库存
                    "quantity" => $base['sku']['quantity']
                ),
                "notice" => $arr['base']['notice'],                                                     //卡券使用提醒
                "description" => $arr['base']['description'],                                           //卡券使用说明
                "center_title"=>$arr['base']['center_title'],
                "center_sub_title"=>$arr['base']['center_sub_title'],
                "center_url"=>$arr['base']['center_url'],
                'use_custom_code' => false,
                'can_give_friend' => true,
                //分享
                'can_share' => false,
                'need_push_on_view' => false,
                'use_all_locations' => true,
                //              "ontice" => $arr['base']['ontice'],
                //             "use_all_locations" => $base['use_all_locations'],
                //             "can_share" => $base['can_share'],
                //              "can_give_friend" => $base['can_give_friend'],
                //               "need_push_on_view" => $base['need_push_on_view'],
            ];
            $udata['base_info'] = json_encode($udata['base_info'],JSON_UNESCAPED_UNICODE);
            $udata['prerogative'] = $arr['prerogative'];                                                //特权说明
            $udata['is_center'] = $arr['base']['is_center'];
            $udata['is_cell1'] = $arr['is_cell1'];
            $udata['is_cell2'] = $arr['is_cell2'];
            $udata['is_cell3'] = $arr['is_cell3'];
            $udata['is_cell4'] = $arr['is_cell4'];
            $udata['is_field2'] = $arr['is_field2'];
            $udata['is_field3'] = $arr['is_field3'];
            $udata['is_locations'] = $arr['base']['is_locations'];
//            $udata['is_pro'] = $arr['base']['is_pro'];
//            $udata['is_custom'] = $arr['base']['is_custom'];
            $udata['is_center'] = $arr['base']['is_center'];
            if ($arr['base']['is_center'] == 1) {
                if ($arr['base']['center'] == 9) {
                    $udata['center_pay'] = 9;
                }else{
                    $adata['center_pay'] = 6;
                }
            }
            if ($arr['supply_bonus'] == 1) {
                $adata['is_bonus'] = 1;
                $udata['bonus_rule'] = json_encode($arr['bonus'], JSON_UNESCAPED_UNICODE);
            }
            if (isset($arr['is_field1'])){
                if ($arr['is_field1'] == 1) {
                    $udata['custom_field1'] = json_encode($arr['custom_field1'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_field2'])) {
                if ($arr['is_field2'] == 1) {
                    $udata['custom_field2'] = json_encode($arr['custom_field2'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_field3'])) {
                if ($arr['is_field3'] == 1) {
                    $udata['custom_field3'] = json_encode($arr['custom_field3'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_cell1'])){
                if ($arr['is_cell1'] == 1) {
                    $udata['custom_cell1'] = json_encode($arr['custom_cell1'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_cell2'])){
                if ($arr['is_cell2'] == 1) {
                    $udata['custom_cell2'] = json_encode($arr['custom_cell2'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_cell3'])){
                if ($arr['is_cell3'] == 1) {
                    $udata['custom_cell3'] = json_encode($arr['custom_cell3'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_cell4'])){
                if ($arr['is_cell4'] == 1) {
                    $udata['custom_cell4'] = json_encode($arr['custom_cell4'], JSON_UNESCAPED_UNICODE);
                }
            }
            if (isset($arr['is_discount'])) {
                if ($arr['is_discount'] == 1) {
                    $udata['discount'] = $arr['discount'];                                            //几折
                }
                $udata['is_discount'] = $arr['is_discount'];
//                else{
//                    $udata['discount'] = 100;
//                }
            }
            $udata['supply_bonus'] = $arr['supply_bonus'];
            $udata['supply_balance'] = $arr['supply_balance'];
            //          $udata['bonus_rule'] = json_encode($arr['bonus'], JSON_UNESCAPED_UNICODE);

            //         $udata['prerogative'] = $arr['prerogative'];                                                //会员卡特权说明
            $udata['update_time'] = time();
            return $udata;
        }
    }



    //基础字段

    //创建时基础字段
    public function base_info($arrs){
//       $arr['is_swipe_card'] = 1;
//       $arr['use_custom_code'] = $arr['use_custom_code'] == 1?true:false;
        $arr['color'] = $this->getcolor($arrs['color']);
        if (empty($arrs['get_limit'])){
            $arr['get_limit'] = 1;
        }else{
            $arr['get_limit'] = $arrs['get_limit'];
        }
        $arr['brand_name'] = $arrs['brand_name'];
        $arr['title'] = $arrs['title'];
        $arr['notice'] = $arrs['notice'];
        $arr['logo_url'] = $arrs['logo_url'];
        $arr['code_type'] = $arrs['code_type'];
        $arr['service_phone'] = $arrs['service_phone'];
        $arr['description'] = $arrs['description'];
        $arr['date_info']['type'] = $arrs['date_info']['type'];
        $arr['sku']['quantity'] = $arrs['sku']['quantity'];
        $arr['use_custom_code'] = false;
        //     $arr['can_give_friend'] = true;
        $arr['code_type'] = $arrs['code_type'];
        //分享
        $arr['can_share'] = false;
        $arr['can_give_friend'] = false;
        $arr['need_push_on_view'] = false;
//        //会员卡顶部中间按钮
        if($arrs['is_center'] == 1){
            if ($arrs['center'] == 9){
                $arr['pay_info']['swipe_card']['is_swipe_card'] = true;
                $arr['center_title'] = '';
                $arr['center_sub_title'] = $arrs['center_sub_title'];
                $arr['center_url'] = '';
            }else{
                $arr['center_title'] = $arrs['center_title'];
                $arr['center_sub_title'] = $arrs['center_sub_title'];
                $arr['center_url'] = $arrs['center_url'];
            }
        }else{
            $arr['center_title'] = '';
            $arr['center_sub_title'] = '';
            $arr['center_url'] = '';
        }

        //自定义类目1
//        if(isset($arr['is_cell2'])){
//            if ($arr['is_cell2'] == 1){
//                $data['member_card']['custom_cell2']['name'] = $arr['custom_cell2']['name'];
//                $data['member_card']['custom_cell2']['tips'] = $arr['custom_cell2']['tips'];
//                $data['member_card']['custom_cell2']['url'] = $arr['custom_cell2']['url'];
//            }
//        }
//        if(isset($arrs['is_cell3'])) {
//            if ($arrs['is_cell3'] == 1) {
//                $arr['custom_url_name'] = $arrs['custom_cell3']['name'];
//                $arr['custom_url_sub_title'] = $arrs['custom_cell3']['tips'];
//                $arr['custom_url'] = $arrs['custom_cell3']['url'];
//            } else {
//                $arr['custom_url_name'] = '';
//                $arr['custom_url_sub_title'] = '';
//                $arr['custom_url'] = '';
//            }
//        }
        //自定义类目1
//        if ($arrs['is_custom'] == 1){
//            $arr['custom_url_name'] = $arrs['custom_url_name'];
//            $arr['custom_url_sub_title'] = $arrs['custom_url_sub_title'];
//            $arr['custom_url'] = $arrs['custom_url'];
//        }else{
//            $arr['custom_url_name'] = '';
//            $arr['custom_url_sub_title'] = '';
//            $arr['custom_url'] = '';
//        }
//        //自定义类目2
//        if ($arrs['is_pro'] == 1){
//            $arr['promotion_url_name'] = $arrs['promotion_url_name'];
//            $arr['promotion_url'] = $arrs['promotion_url'];
//            $arr['promotion_url_sub_title'] = $arrs['promotion_url_sub_title'];
//        }else{
//            $arr['promotion_url_name'] = '';
//            $arr['promotion_url'] = '';
//            $arr['promotion_url_sub_title'] = '';
//        }
        //门店列表
        if ($arrs['is_locations'] == 1){
            $arr['use_all_locations'] = true;
        }
        if ($arrs['is_locations'] == 2){
            //    $arr['use_all_locations'] = false;
            $arr['location_id_list'] = $arrs['location_id_list'];
        }
//
//        $arr['pay_info']['swipe_card']['is_swipe_card'] = $arr['is_swipe_card'] == 1?true:false;
//        $arr['custom_url_name'] = "支持商家";
//        $arr['custom_url'] = "http://card.wunengkeji.com/index.php/substores";
//        $arr['custom_url_sub_title'] = "立即查看";
        return $arr;
    }



    //修改时基础字段
    public function ebase_info($arrs){
        $arr['logo_url'] = $arrs['logo_url'];                               //logo
        $arr['color'] = $this->getcolor($arrs['color']);                    //颜色
        $arr['code_type'] = $arrs['code_type'];
        $arr['notice'] = $arrs['notice'];                                   //使用提醒
//        $arr['brand_name'] = $arrs['brand_name'];                     //商户名称
        $arr['service_phone'] = $arrs['service_phone'];                     //客服电话
        $arr['description'] = $arrs['description'];                         //使用说明
        $arr['code_type'] = $arrs['code_type'];
        //会员卡顶部中间按钮
        if($arrs['is_center'] == 1){
            if ($arrs['center'] == 9){
                $arr['pay_info']['swipe_card']['is_swipe_card'] = true;
                $arr['center_title'] = '';
                $arr['center_sub_title'] = $arrs['center_sub_title'];
                $arr['center_url'] = '';
            }else{
                $arr['center_title'] = $arrs['center_title'];
                $arr['center_sub_title'] = $arrs['center_sub_title'];
                $arr['center_url'] = $arrs['center_url'];
            }
        }else{
            $arr['pay_info']['swipe_card']['is_swipe_card'] = false;
            $arr['center_title'] = '';
            $arr['center_sub_title'] = '';
            $arr['center_url'] = '';
        }

//        if(isset($arrs['is_cell3'])) {
//            if ($arrs['is_cell3'] == 1) {
//                $arr['custom_url_name'] = $arrs['custom_cell3']['name'];
//                $arr['custom_url_sub_title'] = $arrs['custom_cell3']['tips'];
//                $arr['custom_url'] = $arrs['custom_cell3']['url'];
//            } else {
//                $arr['custom_url_name'] = '';
//                $arr['custom_url_sub_title'] = '';
//                $arr['custom_url'] = '';
//            }
//        }

//        //自定义类目1
//        if ($arrs['is_custom'] == 1){
//            $arr['custom_url_name'] = $arrs['custom_url_name'];
//            $arr['custom_url_sub_title'] = $arrs['custom_url_sub_title'];
//            $arr['custom_url'] = $arrs['custom_url'];
//        }else{
//            $arr['custom_url_name'] = '';
//            $arr['custom_url_sub_title'] = '';
//            $arr['custom_url'] = '';
//        }
//        //自定义类目2
//        if ($arrs['is_pro'] == 1){
//            $arr['promotion_url_name'] = $arrs['promotion_url_name'];
//            $arr['promotion_url'] = $arrs['promotion_url'];
//            $arr['promotion_url_sub_title'] = $arrs['promotion_url_sub_title'];
//        }else{
//            $arr['promotion_url_name'] = '';
//            $arr['promotion_url'] = '';
//            $arr['promotion_url_sub_title'] = '';
        //     }
        //门店列表
        if ($arrs['is_locations'] == 1){
            $arr['use_all_locations'] = true;
        }
        if ($arrs['is_locations'] == 2){
            //    $arr['use_all_locations'] = false;
            $arr['location_id_list'] = $arrs['location_id_list'];
        }
        return $arr;
    }

    //积分字段
    public function bonus_rule($arrs){
        $arr['cost_money_unit'] = $arrs['cost_money_unit']*100;
        $arr['increase_bonus'] = $arrs['increase_bonus'];
        $arr['max_increase_bonus'] = $arrs['max_increase_bonus'];
        $arr['init_increase_bonus'] = $arrs['init_increase_bonus'];
        $arr['cost_bonus_unit'] = $arrs['cost_bonus_unit'];
        $arr['reduce_money'] = $arrs['reduce_money']*100;
        $arr['least_money_to_use_bonus'] = $arrs['least_money_to_use_bonus']*100;
        $arr['max_reduce_bonus'] = $arrs['max_reduce_bonus'];
        return $arr;
    }


    //高级字段
    private function advanced_info($arrs){
        $arr['abstract']['abstract'] = $arrs['abstract']['abstract'];
        $arr['abstract']['icon_url_list'] = [$arrs['abstract']['icon_url_list']];
        $arr['text_image_list'] = !empty($arrs['text_image_list'])?$this->advan_imglist($arrs['text_image_list']):[];
        return $arr;
    }

    //高级字段图文处理
    private function advan_imglist($arrs){
        if ($arrs){
//            $img = [];
//            $text = [];
            $img = $arrs['image_url'];
            $text = $arrs['text'];
            $data = [];
            if ($img) {
                foreach ($img as $k => $v) {
                    $data[$k]['image_url'] = $v;
                    $data[$k]['text'] = $text[$k];
                }
            }
            return $data;
        }

    }

    //颜色
    /*
     * 通过接口颜色编号获取实际色值
     *
     * */
    public function getcolor($arr){
        //    return $arr;
        switch($arr){
            //浅绿
            case '#63b359':
                $res = 'Color010';
                return $res;
                break;
            //
            case '#2c9f67':
                $res = 'Color020';
                return $res;
                break;
            //
            case '#509fc9':
                $res = 'Color030';
                return $res;
                break;
            //
            case '#5885cf':
                $res = 'Color040';
                return $res;
                break;
            //
            case '#9062c0':
                $res = 'Color050';
                return $res;
                break;
            //
            case '#d09a45':
                $res = 'Color060';
                return $res;
                break;
            //
            case '#e4b138':
                $res = 'Color070';
                return $res;
                break;
            //
            case '#ee903c':
                $res = 'Color080';
                return $res;
                break;
            //
            case '#f08500':
                $res = 'Color081';
                return $res;
                break;
            //
            case '#a9d92d':
                $res = 'Color082';
                return $res;
                break;
            //
            case '#dd6549':
                $res = 'Color090';
                return $res;
                break;
            //
            case '#cc463d':
                $res = 'Color100';
                return $res;
                break;
            //
            case '#cf3e36':
                $res = 'Color101';
                return $res;
                break;
            //
            case '#5E6671':
                $res = 'Color102';
                return $res;
                break;
            default:
                return 'Color030';
        }

    }


    public function getcolors($arr){
        //    return $arr;
        switch($arr){
            //浅绿
            case "#63b359":
                $res = '1';
                return $res;
                break;
            //
            case "#2c9f67":
                $res = '2';
                return $res;
                break;
            //
            case "#509fc9":
                $res = '3';
                return $res;
                break;
            //
            case "#5885cf":
                $res = '4';
                return $res;
                break;
            //
            case "#9062c0":
                $res = '5';
                return $res;
                break;
            //
            case "#d09a45":
                $res = '6';
                return $res;
                break;
            //
            case "#e4b138":
                $res = '7';
                return $res;
                break;
            //
            case "#ee903c":
                $res = '8';
                return $res;
                break;
            //
            case "#f08500":
                $res = '9';
                return $res;
                break;
            //
            case "#a9d92d":
                $res = '10';
                return $res;
                break;
            //
            case "#dd6549":
                $res = '11';
                return $res;
                break;
            //
            case "#cc463d":
                $res = '12';
                return $res;
                break;
            //
            case "#cf3e36":
                $res = '13';
                return $res;
                break;
            //
            case "#5E6671":
                $res = '14';
                return $res;
                break;
            default:
                return 'Color030';
        }

    }

    /*
     * 创建卡券
     *
     *
     * /
     */
    //使用数量


    //创建图文
    public function creatnews($arr){
        $res = [
            "articles"=>[

                "thumb_media_id"=>$arr['thumb'],
                "title"=>$arr['title'],
                "content"=>$arr['content'],
                "digest"=>$arr['digest'],
                "show_cover_pic"=>1

            ]
        ];
        return $res;
    }

    //群发图文
    public function mass($arr){
        $res = [
            "touser"=>[
                $arr['openid']
            ],
            "mpnews"=>[
                "media_id"=>$arr['media_id']
            ],
            "msgtype"=>"mpnews",
            "send_ignore_reprint"=>0
        ];
        return $res;
    }



    //卡券核销
    public function consumecard($arr){
        $data = array(
            'code'=>$arr['code'],
            'card_id'=>$arr['card_id'],

        );
        return $data;
    }


    //创建卡券
    public function creatcard($arr,$type){
        switch($arr['type']) {
            //团购
            case "5":
                $res = $this->groupon($arr,$type);
                return $res;
                break;
            //代金
            case "1":
                $res = $this->sash($arr,$type);
                return $res;
                break;
            //折扣
            case "2":
                $res = $this->discount($arr,$type);
                return $res;
                break;
            //兑换
            case "3":
                $res = $this->gift($arr,$type);
                return $res;
                break;
            //优惠
            case "4":
                $res = $this->coupon($arr,$type);
                return $res;
                break;
        }

    }

    //创建团购券
    public function groupon($arr,$type){
        //接口数据
        if ($type == 1){
            $data = array(
                'card'=>array(
                    'card_type'=>'GROUPON',
                    'groupon'=>array(
                        'base_info'=>array(
                            'logo_url'=>$arr['logo_url'],               //卡券logo
                            'brand_name'=>$arr['brand_name'],           //商户名称
                            'code_type'=>"CODE_TYPE_QRCODE",            //非自定义code
                            'title'=>$arr['title'],                     //卡券名称
                            'color'=>$this->getcolor($arr['color']),    //颜色
                            'notice'=>$arr['notice'],                   //使用提醒
                            'service_phone'=>$arr['service_phone'],     //客服电话
                            'description'=>$arr['description'],         //使用说明
                            'date_info'=>array(
                                'type'=>$arr['date_info'],           //使用时间
//                                'begin_timestamp'=>strtotime($arr['begin_timestamp']),
//                                'end_timestamp'=>strtotime($arr['end_timestamp']),
                            ),
                            'sku'=>array(
                                'quantity'=>$arr['quantity'],       //库存
                            ),
                            'get_limit'=>$arr['get_limit'],             //领取数量
                            'use_limit'=>$arr['use_limit'],             //使用数量
                            'can_share'=>$arr['can_share']==1?true:false,               //分享
                            'can_give_friend'=>$arr['can_give_friend']==1?true:false,   //转赠
                            /*'location_id_list'=>array(
                                $arr['location_id_list'],           //门店列表
                            ),*/
                            /*'center_title'=>'立即使用',             //中部按钮
                            'center_sub_title'=>'。。。。',
                            'center_url'=>'www.qq.com',*/
                        ),
                        /* 'advanced_info'=>array(
                             'use_condition'=>array(
                                 'accept_category'
                             ),

                         ),*/
                        'deal_detail'=>$arr['conten'],             //团购券详情

                    ),
                ),
            );
            $data['card']['groupon']['advanced_info'] = $this->advanced_info($arr['advanced_info']);
            if ($arr['date_info'] == 'DATE_TYPE_FIX_TIME_RANGE'){
                $data['card']['groupon']['base_info']['date_info']['begin_timestamp'] = strtotime($arr['begin_timestamp']);
                $data['card']['groupon']['base_info']['date_info']['end_timestamp'] = strtotime($arr['end_timestamp']);
            }else{
                $data['card']['groupon']['base_info']['date_info']['fixed_term'] =$arr['fixed_term'];
            }
        }
        //存储数据
        if ($type == 2){
            $data = array(
                        'top_mid'=>Session::get('login_top_mid'),
                'mid'=>$arr['mid'],
                'logo_url' =>$arr['logo_url'],
                'brand_name' =>$arr['brand_name'],
                'times' =>$arr['times'],
                'card_type'=>'GROUPON',
                'title'=>$arr['title'],                    //卡券名称
                'base_info'=>array(
                    'logo_url'=>$arr['logo_url'],               //卡券logo
                    'brand_name'=>$arr['brand_name'],           //商户名称
                    'code_type'=>"CODE_TYPE_QRCODE",            //非自定义code
                    'title'=>$arr['title'],                     //卡券名称
                    'color'=>$arr['color'],                     //颜色
                    'notice'=>$arr['notice'],                   //使用提醒
                    'service_phone'=>$arr['service_phone'],     //客服电话
                    'description'=>$arr['description'],         //使用说明
                    'date_info'=>array(
                        'type'=>$arr['date_info'],           //使用时间
//                        'begin_timestamp'=>strtotime($arr['begin_timestamp']),
//                        'end_timestamp'=>strtotime($arr['end_timestamp']),
                    ),
                    'sku'=>array(
                        'quantity'=>$arr['quantity'],       //库存
                    ),
                    'get_limit'=>$arr['get_limit'],             //领取数量
                    'use_limit'=>$arr['use_limit'],             //使用数量
                    'can_share'=>$arr['can_share']==1?true:false,               //分享
                    'can_give_friend'=>$arr['can_give_friend']==1?true:false,   //转赠
                    /*'location_id_list'=>array(
                        $arr['location_id_list'],           //门店列表
                    ),*/
                    /*'center_title'=>'立即使用',             //中部按钮
                    'center_sub_title'=>'。。。。',
                    'center_url'=>'www.qq.com',*/
                ),
                /* 'advanced_info'=>array(
                      'use_condition'=>array(
                          'accept_category'
                      ),
                ),*/
                'begin_timestamp'=>strtotime($arr['begin_timestamp']),    //生效时间
                'end_timestamp'=>strtotime($arr['end_timestamp']),        //失效时间
                'deal_detail'=>$arr['conten'],             //团购券详情
                'color'=>$this->getcolor($arr['color']),        //背景颜色
                'stocks'=>$arr['quantity'],                      //库存
                'statu'=>0,                                     //状态
                'is_card_xs'=>$arr['is_card_xs'],               //是否显示
                'create_time'=>time(),                            //创建时间
            );
            if ($arr['date_info'] == 'DATE_TYPE_FIX_TIME_RANGE'){
                $data['base_info']['date_info']['begin_timestamp'] = strtotime($arr['begin_timestamp']);
                $data['base_info']['date_info']['end_timestamp'] = strtotime($arr['end_timestamp']);
            }else{
//                $end_time = $arr['fixed_term']*86400;
                $data['end_timestamp'] = strtotime("+1 year");        //失效时间
                $data['base_info']['date_info']['fixed_term'] =$arr['fixed_term'];
                $data['fixed_term'] =$arr['fixed_term'];
            }
            $data['base_info'] = json_encode($data['base_info'],JSON_UNESCAPED_UNICODE);
            $data['advanced_info'] = json_encode($this->advanced_info($arr['advanced_info']),JSON_UNESCAPED_UNICODE);
            $data['get_limit'] = $arr['get_limit'];
            $data['use_limit'] = $arr['use_limit'];

            $data['time_type'] = $arr['date_info'];
            $data['is_pay'] = $arr['is_pay'];
            $data['is_cgive'] = $arr['is_cgive'];
            //          $data['advanced_info'] = json_encode($data['advanced_info'],JSON_UNESCAPED_UNICODE);     use_limit
        }
        return $data;
    }

    private function sashdata($arr){
        $data = [
            "swipe_card"=>array(
                "use_mid_list"=>array(
                    $arr['create_mid']

                ),
                "create_mid"=>$arr['create_mid'],
                "is_swipe_card"=>true
            )
        ];
//        file_put_contents('/data2/html/payos/a009.txt',json_encode($data),8);
        return $data;
    }

    private function sashpass(){
        $data = [
            "center_title"=>"立即使用",
            "center_app_brand_user_name"=> "gh_7195ea80d2e6@app",
            "center_app_brand_pass"=>"pages/index/index",
        ];
    }

    //代金券
    public function sash($arr,$type){
        if ($type == 1){
            $data = [];
            $data = array(
                'card'=>array(
                    'card_type'=>'CASH',
                    'cash'=>array(
                        'base_info'=>array(
                            'logo_url'=>$arr['logo_url'],               //卡券logo
                            'brand_name'=>$arr['brand_name'],           //商户名称
                            'code_type'=>"CODE_TYPE_QRCODE",            //非自定义code
                            'title'=>$arr['title'],                     //卡券名称
                            'color'=>$this->getcolor($arr['color']),    //颜色

                            'notice'=>$arr['notice'],                   //使用提醒
                            'service_phone'=>$arr['service_phone'],     //客服电话
                            'description'=>$arr['description'],         //使用说明
                            'date_info'=>array(
                                'type'=>$arr['date_info'],           //使用时间
//                                'begin_timestamp'=>strtotime($arr['begin_timestamp']),
//                                'end_timestamp'=>strtotime($arr['end_timestamp']),
                            ),
                            'sku'=>array(
                                'quantity'=>$arr['quantity'],       //库存
                            ),
                            'get_limit'=>$arr['get_limit'],             //领取数量
                            'use_limit'=>$arr['use_limit'],             //使用数量
                            'can_share'=>$arr['can_share']==1?true:false,               //分享
                            'can_give_friend'=>$arr['can_give_friend']==1?true:false,   //转赠
                            /*'location_id_list'=>array(
                                $arr['location_id_list'],           //门店列表
                            ),*/
                            /*'center_title'=>'立即使用',             //中部按钮
                            'center_sub_title'=>'。。。。',
                            'center_url'=>'www.qq.com',*/
                        ),
                        /* 'advanced_info'=>array(

                         ),*/
                        'least_cost'=>$arr['least_cost']*100,             //起用金额 （单位为分）
                        'reduce_cost'=>$arr['reduce_cost']*100,           //免减金额 （单位为分）
                    ),
                ),
            );

            $data['card']['cash']['advanced_info'] = $this->advanced_info($arr['advanced_info']);
            if ($arr['is_minus'] == 1){
                $data['card']['cash']['base_info']['pay_info'] = $this->sashdata($arr);
//                    $data['card']['cash']['base_info']['center_title'] = '立即使用';
//                    $data['card']['cash']['base_info']['center_app_brand_user_name'] = 'wx8c3b6fee2a5a0ae9';
//                    $data['card']['cash']['base_info']['center_app_brand_pass'] = 'pages/index/index';
            }
            if ($arr['date_info'] == 'DATE_TYPE_FIX_TIME_RANGE'){
                $data['card']['cash']['base_info']['date_info']['begin_timestamp'] = strtotime($arr['begin_timestamp']);
                $data['card']['cash']['base_info']['date_info']['end_timestamp'] = strtotime($arr['end_timestamp']);
            }else{
                $data['card']['cash']['base_info']['date_info']['fixed_term'] =$arr['fixed_term'];
            }

        }
        if ($type == 2){
            $data = array(
                'mid'=>$arr['mid'],
                'top_mid'=>Session::get('login_top_mid'),
                'brand_name' =>$arr['brand_name'],
                'times' =>$arr['times'],
                'create_mid' =>$arr['create_mid'],
                'logo_url' =>$arr['logo_url'],
                'title'=>$arr['title'],                    //卡券名称
                'card_type'=>'CASH',
                'base_info'=>array(
                    'logo_url'=>$arr['logo_url'],               //卡券logo
                    'brand_name'=>$arr['brand_name'],           //商户名称
                    'code_type'=>"CODE_TYPE_QRCODE",            //非自定义code
                    'pay_info'=>$this->sashdata($arr),
                    'title'=>$arr['title'],                     //卡券名称
                    'color'=>$arr['color'],                     //颜色
                    'notice'=>$arr['notice'],                   //使用提醒
                    'service_phone'=>$arr['service_phone'],     //客服电话
                    'description'=>$arr['description'],         //使用说明
                    'date_info'=>array(
                        'type'=>$arr['date_info'],           //使用时间
//                        'begin_timestamp'=>strtotime($arr['begin_timestamp']),
//                        'end_timestamp'=>strtotime($arr['end_timestamp']),
                    ),
                    'sku'=>array(
                        'quantity'=>$arr['quantity'],       //库存
                    ),
                    'get_limit'=>$arr['get_limit'],             //领取数量
                    'use_limit'=>$arr['use_limit'],             //使用数量
                    'can_share'=>$arr['can_share'],               //分享
                    'can_give_friend'=>$arr['can_give_friend'],   //转赠
                    /*'location_id_list'=>array(
                        $arr['location_id_list'],           //门店列表
                    ),*/
                    /*'center_title'=>'立即使用',             //中部按钮
                    'center_sub_title'=>'。。。。',
                    'center_url'=>'www.qq.com',*/
                ),
                /* 'advanced_info'=>array(
                ),*/
                'is_minus'=>$arr['is_minus'],
                'begin_timestamp'=>strtotime($arr['begin_timestamp']),    //生效时间
                'end_timestamp'=>strtotime($arr['end_timestamp']),        //失效时间
                'least_cost'=>$arr['least_cost'],             //起用金额 （单位为分）
                'reduce_cost'=>$arr['reduce_cost'],           //免减金额 （单位为分）
                'color'=>$this->getcolor($arr['color']),        //背景颜色
                'stocks'=>$arr['quantity'],                      //库存
                'statu'=>0,                                     //状态
                'is_card_xs'=>$arr['is_card_xs'],               //是否显示
                'create_time'=>time(),                            //创建时间
            );
            if ($arr['date_info'] == 'DATE_TYPE_FIX_TIME_RANGE'){
                $data['base_info']['date_info']['begin_timestamp'] = strtotime($arr['begin_timestamp']);
                $data['base_info']['date_info']['end_timestamp'] = strtotime($arr['end_timestamp']);
            }else{
//                $end_time = $arr['fixed_term']*86400;
                $data['end_timestamp'] = strtotime("+1 year");        //失效时间
                $data['base_info']['date_info']['fixed_term'] =$arr['fixed_term'];
                $data['fixed_term'] =$arr['fixed_term'];
            }
            $data['base_info'] = json_encode($data['base_info'],JSON_UNESCAPED_UNICODE);
            $data['advanced_info'] = json_encode($this->advanced_info($arr['advanced_info']),JSON_UNESCAPED_UNICODE);
            $data['get_limit'] = $arr['get_limit'];
            $data['use_limit'] = $arr['use_limit'];

            $data['time_type'] = $arr['date_info'];
            $data['is_pay'] = $arr['is_pay'];
            $data['is_cgive'] = $arr['is_cgive'];
            //          $data['advanced_info'] = json_encode($data['advanced_info'],JSON_UNESCAPED_UNICODE);
        }
        return $data;
    }

//折扣券
    public function discount($arr,$type){
        if ($type == 1){
            $data = array(
                'card'=>array(
                    'card_type'=>'DISCOUNT',
                    'discount'=>array(
                        'base_info'=>array(
                            'logo_url'=>$arr['logo_url'],               //卡券logo
                            'brand_name'=>$arr['brand_name'],           //商户名称
                            'code_type'=>"CODE_TYPE_QRCODE",            //非自定义code
                            'title'=>$arr['title'],                     //卡券名称
                            'color'=>$this->getcolor($arr['color']),    //颜色
                            'notice'=>$arr['notice'],                   //使用提醒
                            'service_phone'=>$arr['service_phone'],     //客服电话
                            'description'=>$arr['description'],         //使用说明
                            'date_info'=>array(
                                'type'=>$arr['date_info'],           //使用时间
//                                'begin_timestamp'=>strtotime($arr['begin_timestamp']),
//                                'end_timestamp'=>strtotime($arr['end_timestamp']),
                            ),
                            'sku'=>array(
                                'quantity'=>$arr['quantity'],       //库存
                            ),
                            'get_limit'=>$arr['get_limit'],             //领取数量
                            'use_limit'=>$arr['use_limit'],             //使用数量
                            'can_share'=>$arr['can_share']==1?true:false,               //分享
                            'can_give_friend'=>$arr['can_give_friend']==1?true:false,   //转赠
                            /*'location_id_list'=>array(
                                $arr['location_id_list'],           //门店列表
                            ),*/
                            /*'center_title'=>'立即使用',             //中部按钮
                            'center_sub_title'=>'。。。。',
                            'center_url'=>'www.qq.com',*/
                        ),
                        /* 'advanced_info'=>array(

                         ),*/
                        'discount'=>100-$arr['discount'],             //折扣 （30就是7折）
                    ),
                ),
            );
            $data['card']['discount']['advanced_info'] = $this->advanced_info($arr['advanced_info']);
            if ($arr['date_info'] == 'DATE_TYPE_FIX_TIME_RANGE'){
                $data['card']['discount']['base_info']['date_info']['begin_timestamp'] = strtotime($arr['begin_timestamp']);
                $data['card']['discount']['base_info']['date_info']['end_timestamp'] = strtotime($arr['end_timestamp']);
            }else{
                $data['card']['discount']['base_info']['date_info']['fixed_term'] =$arr['fixed_term'];
            }
        }
        if ($type == 2){
            $data = array(
                'mid'=>$arr['mid'],
                'top_mid'=>Session::get('login_top_mid'),
                'brand_name' =>$arr['brand_name'],
                'times' =>$arr['times'],
                'logo_url' =>$arr['logo_url'],
                'title'=>$arr['title'],                    //卡券名称
                'card_type'=>'DISCOUNT',
                'base_info'=>array(
                    'logo_url'=>$arr['logo_url'],               //卡券logo
                    'brand_name'=>$arr['brand_name'],           //商户名称
                    'code_type'=>"CODE_TYPE_QRCODE",            //非自定义code
                    'title'=>$arr['title'],                     //卡券名称
                    'color'=>$arr['color'],                     //颜色
                    'notice'=>$arr['notice'],                   //使用提醒
                    'service_phone'=>$arr['service_phone'],     //客服电话
                    'description'=>$arr['description'],         //使用说明
                    'date_info'=>array(
                        'type'=>$arr['date_info'],           //使用时间
//                        'begin_timestamp'=>strtotime($arr['begin_timestamp']),
//                        'end_timestamp'=>strtotime($arr['end_timestamp']),
                    ),
                    'sku'=>array(
                        'quantity'=>$arr['quantity'],       //库存
                    ),
                    'get_limit'=>$arr['get_limit'],             //领取数量
                    'use_limit'=>$arr['use_limit'],             //使用数量
                    'can_share'=>$arr['can_share']==1?true:false,               //分享
                    'can_give_friend'=>$arr['can_give_friend']==1?true:false,   //转赠
                    /*'location_id_list'=>array(
                        $arr['location_id_list'],           //门店列表
                    ),*/
                    /*'center_title'=>'立即使用',             //中部按钮
                    'center_sub_title'=>'。。。。',
                    'center_url'=>'www.qq.com',*/
                ),
                /* 'advanced_info'=>array(

                        ),*/
                'begin_timestamp'=>strtotime($arr['begin_timestamp']),    //生效时间
                'end_timestamp'=>strtotime($arr['end_timestamp']),        //失效时间
                'discount'=>$arr['discount'],             //折扣 （30就是7折）
                'color'=>$this->getcolor($arr['color']),        //背景颜色
                'stocks'=>$arr['quantity'],                      //库存
                'statu'=>0,                                     //状态
                'is_card_xs'=>$arr['is_card_xs'],               //是否显示
                'create_time'=>time(),                            //创建时间
            );
            if ($arr['date_info'] == 'DATE_TYPE_FIX_TIME_RANGE'){
                $data['base_info']['date_info']['begin_timestamp'] = strtotime($arr['begin_timestamp']);
                $data['base_info']['date_info']['end_timestamp'] = strtotime($arr['end_timestamp']);
            }else{
//                $end_time = $arr['fixed_term']*86400;
                $data['end_timestamp'] = strtotime("+1 year");        //失效时间
                $data['base_info']['date_info']['fixed_term'] =$arr['fixed_term'];
                $data['fixed_term'] =$arr['fixed_term'];
            }
            $data['base_info'] = json_encode($data['base_info'],JSON_UNESCAPED_UNICODE);
            $data['advanced_info'] = json_encode($this->advanced_info($arr['advanced_info']),JSON_UNESCAPED_UNICODE);
            $data['get_limit'] = $arr['get_limit'];
            $data['use_limit'] = $arr['use_limit'];
            $data['time_type'] = $arr['date_info'];
            $data['is_pay'] = $arr['is_pay'];
            $data['is_cgive'] = $arr['is_cgive'];
            //      $data['advanced_info'] = json_encode($data['advanced_info'],JSON_UNESCAPED_UNICODE);
        }

        return $data;
    }

//兑换券
    public function gift($arr,$type){
        if ($type == 1){
            $data = array(
                'card'=>array(
                    'card_type'=>'GIFT',
//                    'top_mid'=>Session::get('login_top_mid'),
                    'gift'=>array(
                        'base_info'=>array(
                            'logo_url'=>$arr['logo_url'],               //卡券logo
                            'brand_name'=>$arr['brand_name'],           //商户名称
                            'code_type'=>"CODE_TYPE_QRCODE",            //非自定义code
                            'title'=>$arr['title'],                     //卡券名称
                            'color'=>$this->getcolor($arr['color']),    //颜色
                            'notice'=>$arr['notice'],                   //使用提醒
                            'service_phone'=>$arr['service_phone'],     //客服电话
                            'description'=>$arr['description'],         //使用说明
                            'date_info'=>array(
                                'type'=>$arr['date_info'],           //使用时间
//                                'begin_timestamp'=>strtotime($arr['begin_timestamp']),
//                                'end_timestamp'=>strtotime($arr['end_timestamp']),
                            ),
                            'sku'=>array(
                                'quantity'=>$arr['quantity'],       //库存
                            ),
                            'get_limit'=>$arr['get_limit'],             //领取数量
                            'use_limit'=>$arr['use_limit'],             //使用数量
                            'can_share'=>$arr['can_share']==1?true:false,               //分享
                            'can_give_friend'=>$arr['can_give_friend']==1?true:false,   //转赠
                            /*'location_id_list'=>array(
                                $arr['location_id_list'],           //门店列表
                            ),*/
                            'center_sub_title'=>'使用时请先询问商家',
                        ),
                        /* 'advanced_info'=>array(

                         ),*/
                        'gift'=>$arr['conten'],             //兑换内容
                    ),
                ),
            );
            $data['card']['gift']['advanced_info'] = $this->advanced_info($arr['advanced_info']);
            if ($arr['date_info'] == 'DATE_TYPE_FIX_TIME_RANGE'){
                $data['card']['gift']['base_info']['date_info']['begin_timestamp'] = strtotime($arr['begin_timestamp']);
                $data['card']['gift']['base_info']['date_info']['end_timestamp'] = strtotime($arr['end_timestamp']);
            }else{
                $data['card']['gift']['base_info']['date_info']['fixed_term'] =$arr['fixed_term'];
            }
        }
        if ($type == 2){
            $data = array(
                'mid'=>$arr['mid'],
                'top_mid'=>Session::get('login_top_mid'),
                'brand_name' =>$arr['brand_name'],
                'logo_url' =>$arr['logo_url'],
                'times' =>$arr['times'],
                'title'=>$arr['title'],                    //卡券名称
                'card_type'=>'GIFT',
                'base_info'=>array(
                    'logo_url'=>$arr['logo_url'],               //卡券logo
                    'brand_name'=>$arr['brand_name'],           //商户名称
                    'code_type'=>"CODE_TYPE_QRCODE",            //非自定义code
                    'title'=>$arr['title'],                     //卡券名称
                    'color'=>$arr['color'],                     //颜色
                    'notice'=>$arr['notice'],                   //使用提醒
                    'service_phone'=>$arr['service_phone'],     //客服电话
                    'description'=>$arr['description'],         //使用说明
                    'date_info'=>array(
                        'type'=>$arr['date_info'],           //使用时间
//                        'begin_timestamp'=>strtotime($arr['begin_timestamp']),
//                        'end_timestamp'=>strtotime($arr['end_timestamp']),
                    ),
                    'sku'=>array(
                        'quantity'=>$arr['quantity'],       //库存
                    ),
                    'get_limit'=>$arr['get_limit'],             //领取数量
                    'use_limit'=>$arr['use_limit'],             //使用数量
                    'can_share'=>$arr['can_share'],               //分享
                    'can_give_friend'=>$arr['can_give_friend'],   //转赠
                    /*'location_id_list'=>array(
                        $arr['location_id_list'],           //门店列表
                    ),*/
                    /*'center_title'=>'立即使用',             //中部按钮
                    'center_sub_title'=>'。。。。',
                    'center_url'=>'www.qq.com',*/
                ),
                /* 'advanced_info'=>array(

                        ),*/
                'begin_timestamp'=>strtotime($arr['begin_timestamp']),    //生效时间
                'end_timestamp'=>strtotime($arr['end_timestamp']),        //失效时间
                'gift'=>$arr['conten'],             //兑换内容
                'color'=>$this->getcolor($arr['color']),        //背景颜色
                'stocks'=>$arr['quantity'],                      //库存
                'statu'=>0,                                     //状态
                'is_card_xs'=>$arr['is_card_xs'],               //是否显示
                'create_time'=>time(),                            //创建时间
            );
            if ($arr['date_info'] == 'DATE_TYPE_FIX_TIME_RANGE'){
                $data['base_info']['date_info']['begin_timestamp'] = strtotime($arr['begin_timestamp']);
                $data['base_info']['date_info']['end_timestamp'] = strtotime($arr['end_timestamp']);
            }else{
//                $end_time = $arr['fixed_term']*86400;
                $data['fixed_term'] =$arr['fixed_term'];
                $data['end_timestamp'] = strtotime("+1 year");        //失效时间
                $data['base_info']['date_info']['fixed_term'] =$arr['fixed_term'];
            }
            $data['base_info'] = json_encode($data['base_info'],JSON_UNESCAPED_UNICODE);
            $data['advanced_info'] = json_encode($this->advanced_info($arr['advanced_info']),JSON_UNESCAPED_UNICODE);
            $data['get_limit'] = $arr['get_limit'];
            $data['use_limit'] = $arr['use_limit'];
            $data['time_type'] = $arr['date_info'];
            $data['is_pay'] = $arr['is_pay'];
            $data['is_cgive'] = $arr['is_cgive'];
            //       $data['advanced_info'] = json_encode($data['advanced_info'],JSON_UNESCAPED_UNICODE);
        }

        return $data;
    }

//优惠券
    public function coupon($arr,$type){
        if ($type == 1){
            $data = array(
                'card'=>array(
                    'card_type'=>'GENERAL_COUPON',
                    'general_coupon'=>array(
                        'base_info'=>array(
                            'logo_url'=>$arr['logo_url'],               //卡券logo
                            'brand_name'=>$arr['brand_name'],           //商户名称
                            'code_type'=>"CODE_TYPE_QRCODE",            //非自定义code
                            'title'=>$arr['title'],                     //卡券名称
                            'color'=>$this->getcolor($arr['color']),    //颜色
                            'notice'=>$arr['notice'],                   //使用提醒
                            'service_phone'=>$arr['service_phone'],     //客服电话
                            'description'=>$arr['description'],         //使用说明
                            'date_info'=>array(
                                'type'=>$arr['date_info'],           //使用时间
//                                'begin_timestamp'=>strtotime($arr['begin_timestamp']),
//                                'end_timestamp'=>strtotime($arr['end_timestamp']),
                            ),
                            'sku'=>array(
                                'quantity'=>$arr['quantity'],       //库存
                            ),
                            'get_limit'=>$arr['get_limit'],             //领取数量
                            'use_limit'=>$arr['use_limit'],             //使用数量
                            'can_share'=>$arr['can_share']==1?true:false,               //分享
                            'can_give_friend'=>$arr['can_give_friend']==1?true:false,   //转赠
                            /*'location_id_list'=>array(
                                $arr['location_id_list'],           //门店列表
                            ),*/
                            /*'center_title'=>'立即使用',             //中部按钮
                            'center_sub_title'=>'。。。。',
                            'center_url'=>'www.qq.com',*/
                        ),
                        /* 'advanced_info'=>array(

                         ),*/
                        'default_detail'=>$arr['conten'],             //优惠详情
                    ),
                ),
            );
            $data['card']['general_coupon']['advanced_info'] = $this->advanced_info($arr['advanced_info']);
            if ($arr['date_info'] == 'DATE_TYPE_FIX_TIME_RANGE'){
                $data['card']['general_coupon']['base_info']['date_info']['begin_timestamp'] = strtotime($arr['begin_timestamp']);
                $data['card']['general_coupon']['base_info']['date_info']['end_timestamp'] = strtotime($arr['end_timestamp']);
            }else{
                $data['card']['general_coupon']['base_info']['date_info']['fixed_term'] =$arr['fixed_term'];
            }
        }
        if ($type == 2){
            $data = array(
                'mid'=>$arr['mid'],
                'top_mid'=>Session::get('login_top_mid'),
                'logo_url' =>$arr['logo_url'],
                'brand_name' =>$arr['brand_name'],
                'times' =>$arr['times'],
                'title'=>$arr['title'],                    //卡券名称
                'card_type'=>'GENERAL_COUPON',
                'base_info'=>array(
                    'logo_url'=>$arr['logo_url'],               //卡券logo
                    'brand_name'=>$arr['brand_name'],           //商户名称
                    'code_type'=>"CODE_TYPE_QRCODE",            //非自定义code
                    'title'=>$arr['title'],                     //卡券名称
                    'color'=>$arr['color'],                     //颜色
                    'notice'=>$arr['notice'],                   //使用提醒
                    'service_phone'=>$arr['service_phone'],     //客服电话
                    'description'=>$arr['description'],         //使用说明
                    'date_info'=>array(
                        'type'=>$arr['date_info'],           //使用时间
//                        'begin_timestamp'=>strtotime($arr['begin_timestamp']),
//                        'end_timestamp'=>strtotime($arr['end_timestamp']),
                    ),
                    'sku'=>array(
                        'quantity'=>$arr['quantity'],       //库存
                    ),
                    'get_limit'=>$arr['get_limit'],             //领取数量
                    'use_limit'=>$arr['use_limit'],             //使用数量
                    'can_share'=>$arr['can_share']==1?true:false,               //分享
                    'can_give_friend'=>$arr['can_give_friend']==1?true:false,   //转赠
                    /*'location_id_list'=>array(
                        $arr['location_id_list'],           //门店列表
                    ),*/
                    /*'center_title'=>'立即使用',             //中部按钮
                    'center_sub_title'=>'。。。。',
                    'center_url'=>'www.qq.com',*/
                ),
                /* 'advanced_info'=>array(

                        ),*/
                'begin_timestamp'=>strtotime($arr['begin_timestamp']),    //生效时间
                'end_timestamp'=>strtotime($arr['end_timestamp']),        //失效时间
                'default_detail'=>$arr['conten'],             //优惠详情
                'color'=>$this->getcolor($arr['color']),        //背景颜色
                'stocks'=>$arr['quantity'],                      //库存
                'statu'=>0,                                     //状态
                'is_card_xs'=>$arr['is_card_xs'],               //是否显示
                'create_time'=>time(),                            //创建时间
            );
            if ($arr['date_info'] == 'DATE_TYPE_FIX_TIME_RANGE'){
                $data['base_info']['date_info']['begin_timestamp'] = strtotime($arr['begin_timestamp']);
                $data['base_info']['date_info']['end_timestamp'] = strtotime($arr['end_timestamp']);
            }else{
//                $end_time = $arr['fixed_term']*86400;
                $data['end_timestamp'] = strtotime("+1 year");        //失效时间
                $data['base_info']['date_info']['fixed_term'] =$arr['fixed_term'];
                $data['fixed_term'] =$arr['fixed_term'];
            }
            $data['base_info'] = json_encode($data['base_info'],JSON_UNESCAPED_UNICODE);
            $data['advanced_info'] = json_encode($this->advanced_info($arr['advanced_info']),JSON_UNESCAPED_UNICODE);
            $data['get_limit'] = $arr['get_limit'];
            $data['use_limit'] = $arr['use_limit'];
            $data['time_type'] = $arr['date_info'];
            $data['is_pay'] = $arr['is_pay'];
            $data['is_cgive'] = $arr['is_cgive'];
//        $data['advanced_info'] = json_encode($data['advanced_info'],JSON_UNESCAPED_UNICODE);
        }

        return $data;
    }

//    //修改处理
//    public function editorcard($arr,$type){
//        switch($arr['card_type']) {
//            //团购
//            case "GROUPON":
//                $res = $this->groupone($arr,$type);
//                break;
//            //代金
//            case "CASH":
//                $res = $this->sashe($arr,$type);
//                break;
//            //折扣
//            case "DISCOUNT":
//                $res = $this->discounte($arr,$type);
//                break;
//            //兑换
//            case "GIFT":
//                $res = $this->gifte($arr,$type);
//                break;
//            //优惠
//            case "GENERAL_COUPON":
//                $res = $this->coupone($arr,$type);
//                break;
//        }
//        return $res;
//    }
//
//    //团购券修改
//    public function groupone($arr,$type){
//        //接口数据
//        if ($type == 1){
//            $data = array(
//
//                'card_id'=>$arr['card_id'],
//                'groupon'=>array(
//                    'base_info'=>array(
//                        'logo_url'=>$arr['logo_url'],               //卡券logo
//                        'brand_name'=>$arr['brand_name'],           //商户名称
//                        'code_type'=>$arr['code_type'],             //非自定义code
//                        'title'=>$arr['title'],                     //卡券名称
//                        'color'=>$this->getcolor($arr['color']),    //颜色
//                        'notice'=>$arr['notice'],                   //使用提醒
//                        'service_phone'=>$arr['service_phone'],     //客服电话
//                        'description'=>$arr['description'],         //使用说明
//                        'date_info'=>array(
//                            'type'=>$arr['date_info'],           //使用时间
//                            'begin_timestamp'=>strtotime($arr['begin_timestamp']),
//                            'end_timestamp'=>strtotime($arr['end_timestamp']),
//                        ),
//                        'sku'=>array(
//                            'quantity'=>$arr['quantity'],       //库存
//                        ),
//                        'get_limit'=>$arr['get_limit'],             //领取数量
//                        'use_limit'=>$arr['use_limit'],             //使用数量
//                        'can_share'=>$arr['can_share']==1?true:false,               //分享
//                        'can_give_friend'=>$arr['can_give_friend']==1?true:false,   //转赠
//                        'location_id_list'=>array(
//                            $arr['location_id_list'],           //门店列表
//                        ),
////                        'center_title'=>'立即使用',             //中部按钮
////                        'center_sub_title'=>'。。。。',
////                        'center_url'=>'www.qq.com',
//                    ),
//                    /* 'advanced_info'=>array(
//                         'use_condition'=>array(
//                             'accept_category'
//                         ),
//
//                     ),*/
//                    'deal_detail'=>$arr['conten'],             //团购券详情
//
//                ),
//            );
//            return $data;
//        }
//        //存储数据
//        if ($type == 2){
//            $data = array(
//                'mid'=>$arr['mid'],
//                'card_id'=>$arr['card_id'],
//                'logo_url'=>$arr['logo_url'],               //卡券logo
//                'title'=>$arr['title'],                    //卡券名称
//                'base_info'=>array(
//                    'logo_url'=>$arr['logo_url'],               //卡券logo
//                    'brand_name'=>$arr['brand_name'],           //商户名称
//                    'code_type'=>$arr['code_type'],             //非自定义code
//                    'title'=>$arr['title'],                     //卡券名称
//                    'color'=>$arr['color'],                     //颜色
//                    'notice'=>$arr['notice'],                   //使用提醒
//                    'service_phone'=>$arr['service_phone'],     //客服电话
//                    'description'=>$arr['description'],         //使用说明
//                    'date_info'=>array(
//                        $arr['date_info'],           //使用时间
//                    ),
//                    'sku'=>array(
//                        'quantity'=>$arr['quantity'],       //库存
//                    ),
//                    'get_limit'=>$arr['get_limit'],             //领取数量
//                    'use_limit'=>$arr['use_limit'],             //使用数量
//                    'can_share'=>$arr['can_share']==1?true:false,               //分享
//                    'can_give_friend'=>$arr['can_give_friend']==1?true:false,   //转赠
//                    'location_id_list'=>array(
//                        $arr['location_id_list'],           //门店列表
//                    ),
////                    'center_title'=>'立即使用',             //中部按钮
////                    'center_sub_title'=>'。。。。',
////                    'center_url'=>'www.qq.com',
//                ),
//                /* 'advanced_info'=>array(
//                      'use_condition'=>array(
//                          'accept_category'
//                      ),
//                ),*/
//                'deal_detail'=>$arr['conten'],             //团购券详情
//                'color'=>$this->getcolor($arr['color']),        //背景颜色
//                'stocks'=>$arr['quantity'],                      //库存
//                'statu'=>0,                                     //状态
//                'is_card_xs'=>$arr['is_card_xs'],               //是否显示
//                'creatte_ime'=>time(),                            //创建时间
//            );
//            return $data;
//        }
//
//    }
//
//    //代金券修改
//    public function sashe($arr,$type){
//        if ($type == 1){
//            $data = array(
//                'card_id'=>$arr['card_id'],
//                'cash'=>array(
//                    'base_info'=>array(
//                        'logo_url'=>$arr['logo_url'],               //卡券logo
//                        'brand_name'=>$arr['brand_name'],           //商户名称
//                        'code_type'=>$arr['code_type'],             //非自定义code
//                        'title'=>$arr['title'],                     //卡券名称
//                        'color'=>$this->getcolor($arr['color']),    //颜色
//                        'notice'=>$arr['notice'],                   //使用提醒
//                        'service_phone'=>$arr['service_phone'],     //客服电话
//                        'description'=>$arr['description'],         //使用说明
//                        'date_info'=>array(
//                            'type'=>$arr['date_info'],           //使用时间
//                            'begin_timestamp'=>strtotime($arr['begin_timestamp']),
//                            'end_timestamp'=>strtotime($arr['end_timestamp']),
//                        ),
//                        'sku'=>array(
//                            'quantity'=>$arr['quantity'],       //库存
//                        ),
//                        'get_limit'=>$arr['get_limit'],             //领取数量
//                        'use_limit'=>$arr['use_limit'],             //使用数量
//                        'can_share'=>$arr['can_share']==1?true:false,               //分享
//                        'can_give_friend'=>$arr['can_give_friend']==1?true:false,   //转赠
//                        'location_id_list'=>array(
//                            $arr['location_id_list'],           //门店列表
//                        ),
////                        'center_title'=>'立即使用',             //中部按钮
////                        'center_sub_title'=>'。。。。',
////                        'center_url'=>'www.qq.com',
//                    ),
//                    /* 'advanced_info'=>array(
//
//                     ),*/
//                    'least_cost'=>$arr['least_cost'],             //起用金额 （单位为分）
//                    'reduce_cost'=>$arr['reduce_cost'],           //免减金额 （单位为分）
//                ),
//            );
//        }
//        if ($type == 2){
//            $data = array(
//                'mid'=>$arr['mid'],
//                'card_id'=>$arr['card_id'],
//                'logo_url'=>$arr['logo_url'],               //卡券logo
//                'title'=>$arr['title'],                    //卡券名称
//                'base_info'=>array(
//                    'logo_url'=>$arr['logo_url'],               //卡券logo
//                    'brand_name'=>$arr['brand_name'],           //商户名称
//                    'code_type'=>$arr['code_type'],             //非自定义code
//                    'title'=>$arr['title'],                     //卡券名称
//                    'color'=>$arr['color'],                     //颜色
//                    'notice'=>$arr['notice'],                   //使用提醒
//                    'service_phone'=>$arr['service_phone'],     //客服电话
//                    'description'=>$arr['description'],         //使用说明
//                    'date_info'=>array(
//                        'type'=>$arr['date_info'],           //使用时间
//                        'begin_timestamp'=>strtotime($arr['begin_timestamp']),
//                        'end_timestamp'=>strtotime($arr['end_timestamp']),
//                    ),
//                    'sku'=>array(
//                        'quantity'=>$arr['quantity'],       //库存
//                    ),
//                    'get_limit'=>$arr['get_limit'],             //领取数量
//                    'use_limit'=>$arr['use_limit'],             //使用数量
//                    'can_share'=>$arr['can_share'],               //分享
//                    'can_give_friend'=>$arr['can_give_friend'],   //转赠
//                    'location_id_list'=>array(
//                        $arr['location_id_list'],           //门店列表
//                    ),
//                    /*'center_title'=>'立即使用',             //中部按钮
//                    'center_sub_title'=>'。。。。',
//                    'center_url'=>'www.qq.com',*/
//                ),
//                /* 'advanced_info'=>array(
//                ),*/
//                'least_cost'=>$arr['least_cost'],             //起用金额 （单位为分）
//                'reduce_cost'=>$arr['reduce_cost'],           //免减金额 （单位为分）
//                'color'=>$this->getcolor($arr['color']),        //背景颜色
//                'stocks'=>$arr['quantity'],                      //库存
//                'statu'=>0,                                     //状态
//                'is_card_xs'=>$arr['is_card_xs'],               //是否显示
//                'create_time'=>time(),                            //创建时间
//            );
//        }
//        return $data;
//    }
//
//    //折扣券修改
//    public function discounte($arr,$type){
//        if ($type == 1){
//            $data = array(
//                'card_id'=>$arr['card_id'],
//                'discount'=>array(
//                    'base_info'=>array(
//                        'logo_url'=>$arr['logo_url'],               //卡券logo
//                        'brand_name'=>$arr['brand_name'],           //商户名称
//                        'code_type'=>$arr['code_type'],             //非自定义code
//                        'title'=>$arr['title'],                     //卡券名称
//                        'color'=>$arr['color'],                     //颜色
//                        'notice'=>$arr['notice'],                   //使用提醒
//                        'service_phone'=>$arr['service_phone'],     //客服电话
//                        'description'=>$arr['description'],         //使用说明
//                        'date_info'=>array(
//                            'type'=>$arr['date_info'],           //使用时间
//                            'begin_timestamp'=>strtotime($arr['begin_timestamp']),
//                            'end_timestamp'=>strtotime($arr['end_timestamp']),
//                        ),
//                        'sku'=>array(
//                            'quantity'=>$arr['quantity'],       //库存
//                        ),
//                        'get_limit'=>$arr['get_limit'],             //领取数量
//                        'use_limit'=>$arr['use_limit'],             //使用数量
//                        'can_share'=>$arr['can_share']==1?true:false,               //分享
//                        'can_give_friend'=>$arr['can_give_friend']==1?true:false,   //转赠
//                        'location_id_list'=>array(
//                            $arr['location_id_list'],           //门店列表
//                        ),
////                        'center_title'=>'立即使用',             //中部按钮
////                        'center_sub_title'=>'。。。。',
////                        'center_url'=>'www.qq.com',
//                    ),
//                    /* 'advanced_info'=>array(
//
//                     ),*/
//                    'discount'=>$arr['conten'],             //折扣 （30就是7折）
//                ),
//            );
//        }
//        if ($type == 2){
//            $data = array(
//                'mid'=>$arr['mid'],
//                'card_id'=>$arr['card_id'],
//                'logo_url'=>$arr['logo_url'],               //卡券logo
//                'title'=>$arr['title'],                    //卡券名称
//                'base_info'=>array(
//                    'logo_url'=>$arr['logo_url'],               //卡券logo
//                    'brand_name'=>$arr['brand_name'],           //商户名称
//                    'code_type'=>$arr['code_type'],             //非自定义code
//                    'title'=>$arr['title'],                     //卡券名称
//                    'color'=>$arr['color'],                     //颜色
//                    'notice'=>$arr['notice'],                   //使用提醒
//                    'service_phone'=>$arr['service_phone'],     //客服电话
//                    'description'=>$arr['description'],         //使用说明
//                    'date_info'=>array(
//                        $arr['date_info'],           //使用时间
//                    ),
//                    'sku'=>array(
//                        'quantity'=>$arr['quantity'],       //库存
//                    ),
//                    'get_limit'=>$arr['get_limit'],             //领取数量
//                    'use_limit'=>$arr['use_limit'],             //使用数量
//                    'can_share'=>$arr['can_share']==1?true:false,               //分享
//                    'can_give_friend'=>$arr['can_give_friend']==1?true:false,   //转赠
//                    'location_id_list'=>array(
//                        $arr['location_id_list'],           //门店列表
//                    ),
////                    'center_title'=>'立即使用',             //中部按钮
////                    'center_sub_title'=>'。。。。',
////                    'center_url'=>'www.qq.com',
//                ),
//                /* 'advanced_info'=>array(
//
//                        ),*/
//                'discount'=>$arr['conten'],             //折扣 （30就是7折）
//                'color'=>$this->getcolor($arr['color']),        //背景颜色
//                'stocks'=>$arr['quantity'],                      //库存
//                'statu'=>0,                                     //状态
//                'is_card_xs'=>$arr['is_card_xs'],               //是否显示
//                'create_time'=>time(),                            //创建时间
//            );
//        }
//
//        return $data;
//    }
//
//    //兑换券修改
//    public function gifte($arr,$type){
//        if ($type == 1){
//            $data = array(
//                'card_id'=>$arr['card_id'],
//                'gift'=>array(
//                    'base_info'=>array(
//                        'logo_url'=>$arr['logo_url'],               //卡券logo
//                        //                   'color'=>$arr['color'],                     //颜色
//                        'notice'=>$arr['notice'],                   //使用提醒
//                        'service_phone'=>$arr['service_phone'],     //客服电话
//                        'description'=>$arr['description'],         //使用说明
//                        /*'sku'=>array(
//                            'quantity'=>$arr['quantity'],       //库存
//                        ),
//                        'location_id_list'=>array(
//                            $arr['location_id_list'],           //门店列表
//                        ),*/
//                    ),
//                    /* 'advanced_info'=>array(
//
//                     ),*/
//                    'gift'=>$arr['gift'],             //兑换内容
//                ),
//            );
//        }
//        if ($type == 2){
//            $data = array(
//                'mid'=>$arr['mid'],
//                'card_id'=>$arr['card_id'],
//                'logo_url'=>$arr['logo_url'],               //卡券logo
//                'title'=>$arr['title'],                    //卡券名称
//                'base_info'=>array(
//                    'logo_url'=>$arr['logo_url'],               //卡券logo
//                    'brand_name'=>$arr['brand_name'],           //商户名称
//                    'code_type'=>$arr['code_type'],             //非自定义code
//                    'title'=>$arr['title'],                     //卡券名称
//                    'color'=>$arr['color'],                     //颜色
//                    'notice'=>$arr['notice'],                   //使用提醒
//                    'service_phone'=>$arr['service_phone'],     //客服电话
//                    'description'=>$arr['description'],         //使用说明
//                    'date_info'=>array(
//                        'type'=>$arr['date_info'],           //使用时间
//                        'begin_timestamp'=>$arr['begin_timestamp'],
//                        'end_timestamp'=>$arr['end_timestamp'],
//                    ),
//                    'sku'=>array(
//                        'quantity'=>$arr['quantity'],       //库存
//                    ),
//                    'get_limit'=>$arr['get_limit'],             //领取数量
//                    'use_limit'=>$arr['use_limit'],             //使用数量
//                    'can_share'=>$arr['can_share'],               //分享
//                    'can_give_friend'=>$arr['can_give_friend'],   //转赠
//                    'location_id_list'=>array(
//                        $arr['location_id_list'],           //门店列表
//                    ),
//                    /*'center_title'=>'立即使用',             //中部按钮
//                    'center_sub_title'=>'。。。。',
//                    'center_url'=>'www.qq.com',*/
//                ),
//                /* 'advanced_info'=>array(
//
//                        ),*/
//                'gift'=>$arr['gift'],             //兑换内容
//                'color'=>$this->getcolor($arr['color']),        //背景颜色
//                'stocks'=>$arr['quantity'],                      //库存
//                'statu'=>0,                                     //状态
//                'is_card_xs'=>$arr['is_card_xs'],               //是否显示
//                'create_time'=>time(),                            //创建时间
//            );
//            $data['base_info'] = json_encode($data['base_info'],JSON_UNESCAPED_UNICODE);
//            //          $data['advanced_info'] = json_encode($data['advanced_info'],JSON_UNESCAPED_UNICODE);
//        }
//
//        return $data;
//    }
//
//    //优惠券修改
//    public function coupone($arr,$type){
//        if ($type == 1){
//            $data = array(
//                'card_id'=>$arr['card_id'],
//                'general_coupon'=>array(
//                    'base_info'=>array(
//                        'logo_url'=>$arr['logo_url'],               //卡券logo
//                        'brand_name'=>$arr['brand_name'],           //商户名称
//                        'code_type'=>$arr['code_type'],             //非自定义code
//                        'title'=>$arr['title'],                     //卡券名称
//                        'color'=>$arr['color'],                     //颜色
//                        'notice'=>$arr['notice'],                   //使用提醒
//                        'service_phone'=>$arr['service_phone'],     //客服电话
//                        'description'=>$arr['description'],         //使用说明
//                        'date_info'=>array(
//                            'type'=>$arr['date_info'],           //使用时间
//                            'begin_timestamp'=>strtotime($arr['begin_timestamp']),
//                            'end_timestamp'=>strtotime($arr['end_timestamp']),
//                        ),
//                        'sku'=>array(
//                            'quantity'=>$arr['quantity'],       //库存
//                        ),
//                        'get_limit'=>$arr['get_limit'],             //领取数量
//                        'use_limit'=>$arr['use_limit'],             //使用数量
//                        'can_share'=>$arr['can_share']==1?true:false,               //分享
//                        'can_give_friend'=>$arr['can_give_friend']==1?true:false,   //转赠
//                        'location_id_list'=>array(
//                            $arr['location_id_list'],           //门店列表
//                        ),
////                        'center_title'=>'立即使用',             //中部按钮
////                        'center_sub_title'=>'。。。。',
////                        'center_url'=>'www.qq.com',
//                    ),
//                    /* 'advanced_info'=>array(
//
//                     ),*/
//                    'default_detail'=>$arr['default_detail'],             //优惠详情
//                ),
//            );
//        }
//        if ($type == 2){
//            $data = array(
//                'mid'=>$arr['mid'],
//                'card_id'=>$arr['card_id'],
//                'logo_url'=>$arr['logo_url'],               //卡券logo
//                'title'=>$arr['title'],                    //卡券名称
//                'base_info'=>array(
//                    'logo_url'=>$arr['logo_url'],               //卡券logo
//                    'brand_name'=>$arr['brand_name'],           //商户名称
//                    'code_type'=>$arr['code_type'],             //非自定义code
//                    'title'=>$arr['title'],                     //卡券名称
//                    'color'=>$arr['color'],                     //颜色
//                    'notice'=>$arr['notice'],                   //使用提醒
//                    'service_phone'=>$arr['service_phone'],     //客服电话
//                    'description'=>$arr['description'],         //使用说明
//                    'date_info'=>array(
//                        $arr['date_info'],           //使用时间
//                    ),
//                    'sku'=>array(
//                        'quantity'=>$arr['quantity'],       //库存
//                    ),
//                    'get_limit'=>$arr['get_limit'],             //领取数量
//                    'use_limit'=>$arr['use_limit'],             //使用数量
//                    'can_share'=>$arr['can_share']==1?true:false,               //分享
//                    'can_give_friend'=>$arr['can_give_friend']==1?true:false,   //转赠
//                    'location_id_list'=>array(
//                        $arr['location_id_list'],           //门店列表
//                    ),
////                    'center_title'=>'立即使用',             //中部按钮
////                    'center_sub_title'=>'。。。。',
////                    'center_url'=>'www.qq.com',
//                ),
//                /* 'advanced_info'=>array(
//
//                        ),*/
//                'default_detail'=>$arr['default_detail'],             //优惠详情
//
//                'color'=>$this->getcolor($arr['color']),        //背景颜色
//                'stocks'=>$arr['quantity'],                      //库存
//                'statu'=>0,                                     //状态
//                'is_card_xs'=>$arr['is_card_xs'],               //是否显示
//                'create_time'=>time(),                            //创建时间
//            );
//        }
//
//        return $data;
//    }

}
